import java.util.Arrays;

public class Solution {
    public int numRescueBoats(int[] people, int limit) {

        Arrays.sort(people);
        int light=0;
        int heavy=people.length-1;
        int ans=0;
        while(light<=heavy){
            if(people[light]+people[heavy]<=limit){
                //最轻能与最重装一辆船
                light++;
            }
            //最重自己装一辆船
            heavy--;
            ans++;
        }
        return ans;
    }
}